<?php

require "vendor/autoload.php";

use PhpOffice\PhpWord\TemplateProcessor;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\IOFactory;

$phpword = new PhpWord();

$section = $phpword -> addSection();

$phpword -> addTitleStyle(0,array("size"=>16,"name"=>"黑体","bold"=>true),["alignment"=>"center","spacing"=>160,"spacingLineRule"=>"exact",'indentation' => array('firstline' => 130.41)]);
$phpword -> addTitleStyle(0,array("size"=>16,"name"=>"黑体","bold"=>true),["alignment"=>"center"]);
$section -> addTitle("中文摘要",0);


// Define styles
$fontStyle12 = array('spaceAfter' => 60, 'size' => 12);
$fontStyle10 = array('size' => 10);
$phpword->addTitleStyle(null, array('size' => 17, 'bold' => false));
$phpword->addTitleStyle(1, array('size' => 20, 'color' => '333333', 'bold' => true));
$phpword->addTitleStyle(2, array('size' => 16, 'color' => '666666'));
$phpword->addTitleStyle(3, array('size' => 14, 'italic' => true));
$phpword->addTitleStyle(4, array('size' => 12));
// Add text elements
$section->addTitle('Table of contents 1', 3);
$section->addTextBreak(2);
// Add TOC #1
$toc = $section->addTOC($fontStyle12);
$section->addTextBreak(2);
// Filler
$section->addText('Text between TOC');
$section->addTextBreak(2);
// Add TOC #1
$section->addText('Table of contents 2');
$section->addTextBreak(2);
$toc2 = $section->addTOC($fontStyle10);
$toc2->setMinDepth(2);
$toc2->setMaxDepth(3);
// Add Titles
$section->addPageBreak();
$section->addTitle('Foo n Bar', 1);
$section->addText('Some text...');
$section->addTextBreak(2);
$section->addTitle('I am a Subtitle of Title 1', 2);
$section->addTextBreak(2);
$section->addText('Some more text...');
$section->addTextBreak(2);
$section->addTitle('Another Title (Title 2)', 1);
$section->addText('Some text...');
$section->addPageBreak();
$section->addTitle('I am Title 3', 1);
$section->addText('And more text...');
$section->addTextBreak(2);
$section->addTitle('I am a Subtitle of Title 3', 2);
$section->addText('Again and again, more text...');
$section->addTitle('Subtitle 3.1.1', 3);
$section->addText('Text');
$section->addTitle('Subtitle 3.1.1.1', 4);
$section->addText('Text');
$section->addTitle('Subtitle 3.1.1.2', 4);
$section->addText('Text');
$section->addTitle('Subtitle 3.1.2', 3);
$section->addText('Text');
//获取样式
//$word = IOFactory::load("docx/t01.docx");
ob_start();
var_dump($phpword);
$r = ob_get_clean();
file_put_contents('b.json',$r);

$writer = IOFactory::createWriter($phpword,'Word2007');
$writer->save("d01.docx");

